package org.liveboardgames.agricola.control.commands
{
    import com.adobe.cairngorm.commands.ICommand;
    import com.adobe.cairngorm.control.CairngormEvent;
    
    import mx.controls.Alert;
    import mx.rpc.IResponder;
    import mx.rpc.events.FaultEvent;
    
    import org.liveboardgames.agricola.control.delegates.AddFarmElementDelegate;
    import org.liveboardgames.agricola.control.events.AddFarmElementEvent;
    
    public class AddFarmElementCommand implements ICommand, IResponder
    {
        public function execute(event:CairngormEvent):void
        {
            var delegate:AddFarmElementDelegate = new AddFarmElementDelegate(this);
            var addFarmElementEvent:AddFarmElementEvent = AddFarmElementEvent(event);
            delegate.addFarmElement(addFarmElementEvent.farmTile, addFarmElementEvent.farmElement);
        }
        
        public function result(data:Object):void
        {
            // Do nothing, the model should be updated by the delegate
        }
        
        public function fault(info:Object):void
        {
            var faultEvent:FaultEvent = FaultEvent(info);
            Alert.show("Could not add new farm element", "Error");
        }
    
    }
}